#ifndef _PLATFORM_UTILS_H_
#define _PLATFORM_UTILS_H_

#include <Library/PcdLib.h>

enum {
	NORTH = 0,
	SOUTH,
	EAST,
	WEST
};

CONST UINT32 TlmmTilesAddr[] = {0x03900000, 0x03D00000, 0x03500000, 0x03100000};

#define TLMM_ADDR_OFFSET_FOR_PIN(x) (0x1000 * x)

#define TLMM_PIN_CONTROL_REGISTER 0
#define TLMM_PIN_IO_REGISTER 4
#define TLMM_PIN_INTERRUPT_CONFIG_REGISTER 8
#define TLMM_PIN_INTERRUPT_STATUS_REGISTER 0xC
#define TLMM_PIN_INTERRUPT_TARGET_REGISTER TLMM_PIN_INTERRUPT_CONFIG_REGISTER

#define SMMU_BASE 0x15000000

#define SMMU_CTX_BANK_SIZE 0x1000

#define SMMU_CTX_BANK_0_OFFSET 0x80000
#define SMMU_CTX_BANK_SCTLR_OFFSET 0x0
#define SMMU_CTX_BANK_TTBR0_0_OFFSET 0x20
#define SMMU_CTX_BANK_TTBR0_1_OFFSET 0x24
#define SMMU_CTX_BANK_TTBR1_0_OFFSET 0x28
#define SMMU_CTX_BANK_TTBR1_1_OFFSET 0x2C
#define SMMU_CTX_BANK_MAIR0_OFFSET 0x38
#define SMMU_CTX_BANK_MAIR1_OFFSET 0x3C
#define SMMU_CTX_BANK_TTBCR_OFFSET 0x30

#define SMMU_NON_CCA_SCTLR 0xE0
#define SMMU_CCA_SCTLR 0x9F00E0

#define UFS_CTX_BANK 1

#define APSS_WDT_BASE 0x17C10000
#define APSS_WDT_ENABLE_OFFSET 0x8

VOID PlatformInitialize();

STATIC CONST UINT8 sm8150_pin_tiles[] = {
	[0] = SOUTH,
	[1] = SOUTH,
	[2] = SOUTH,
	[3] = SOUTH,
	[4] = SOUTH,
	[5] = SOUTH,
	[6] = SOUTH,
	[7] = SOUTH,
	[8] = NORTH,
	[9] = NORTH,
	[10] = NORTH,
	[11] = NORTH,
	[12] = NORTH,
	[13] = NORTH,
	[14] = NORTH,
	[15] = NORTH,
	[16] = NORTH,
	[17] = NORTH,
	[18] = NORTH,
	[19] = NORTH,
	[20] = NORTH,
	[21] = EAST,
	[22] = EAST,
	[23] = EAST,
	[24] = EAST,
	[25] = EAST,
	[26] = EAST,
	[27] = EAST,
	[28] = EAST,
	[29] = EAST,
	[30] = EAST,
	[31] = NORTH,
	[32] = NORTH,
	[33] = NORTH,
	[34] = NORTH,
	[35] = NORTH,
	[36] = NORTH,
	[37] = NORTH,
	[38] = SOUTH,
	[39] = NORTH,
	[40] = NORTH,
	[41] = NORTH,
	[42] = NORTH,
	[43] = EAST,
	[44] = EAST,
	[45] = EAST,
	[46] = EAST,
	[47] = EAST,
	[48] = EAST,
	[49] = EAST,
	[50] = EAST,
	[51] = SOUTH,
	[52] = SOUTH,
	[53] = SOUTH,
	[54] = SOUTH,
	[55] = SOUTH,
	[56] = SOUTH,
	[57] = SOUTH,
	[58] = SOUTH,
	[59] = SOUTH,
	[60] = SOUTH,
	[61] = SOUTH,
	[62] = SOUTH,
	[63] = SOUTH,
	[64] = SOUTH,
	[65] = SOUTH,
	[66] = SOUTH,
	[67] = SOUTH,
	[68] = SOUTH,
	[69] = SOUTH,
	[70] = SOUTH,
	[71] = SOUTH,
	[72] = SOUTH,
	[73] = SOUTH,
	[74] = SOUTH,
	[75] = SOUTH,
	[76] = SOUTH,
	[77] = SOUTH,
	[78] = SOUTH,
	[79] = SOUTH,
	[80] = SOUTH,
	[81] = SOUTH,
	[82] = SOUTH,
	[83] = NORTH,
	[84] = NORTH,
	[85] = NORTH,
	[86] = NORTH,
	[87] = EAST,
	[88] = NORTH,
	[89] = NORTH,
	[90] = NORTH,
	[91] = NORTH,
	[92] = NORTH,
	[93] = NORTH,
	[94] = NORTH,
	[95] = NORTH,
	[96] = NORTH,
	[97] = NORTH,
	[98] = SOUTH,
	[99] = SOUTH,
	[100] = SOUTH,
	[101] = SOUTH,
	[102] = NORTH,
	[103] = NORTH,
	[104] = NORTH,
	[105] = WEST,
	[106] = WEST,
	[107] = WEST,
	[108] = WEST,
	[109] = WEST,
	[110] = WEST,
	[111] = WEST,
	[112] = WEST,
	[113] = WEST,
	[114] = SOUTH,
	[115] = SOUTH,
	[116] = SOUTH,
	[117] = SOUTH,
	[118] = SOUTH,
	[119] = SOUTH,
	[120] = SOUTH,
	[121] = SOUTH,
	[122] = SOUTH,
	[123] = SOUTH,
	[124] = SOUTH,
	[125] = WEST,
	[126] = SOUTH,
	[127] = SOUTH,
	[128] = SOUTH,
	[129] = SOUTH,
	[130] = SOUTH,
	[131] = SOUTH,
	[132] = SOUTH,
	[133] = SOUTH,
	[134] = SOUTH,
	[135] = SOUTH,
	[136] = SOUTH,
	[137] = SOUTH,
	[138] = SOUTH,
	[139] = SOUTH,
	[140] = SOUTH,
	[141] = SOUTH,
	[142] = SOUTH,
	[143] = SOUTH,
	[144] = SOUTH,
	[145] = SOUTH,
	[146] = SOUTH,
	[147] = SOUTH,
	[148] = SOUTH,
	[149] = SOUTH,
	[150] = SOUTH,
	[151] = SOUTH,
	[152] = SOUTH,
	[153] = SOUTH,
	[154] = SOUTH,
	[155] = WEST,
	[156] = WEST,
	[157] = WEST,
	[158] = WEST,
	[159] = WEST,
	[160] = WEST,
	[161] = WEST,
	[162] = WEST,
	[163] = WEST,
	[164] = WEST,
	[165] = WEST,
	[166] = WEST,
	[167] = WEST,
	[168] = WEST,
	[169] = NORTH,
	[170] = NORTH,
	[171] = NORTH,
	[172] = NORTH,
	[173] = NORTH,
	[174] = NORTH,
};

#endif /* _PLATFORM_UTILS_H_ */